//
// Created by dong on 2025/10/22.
//

#include "SLayout.h"

SLayout::SLayout()
{
    menu_area = {0,0,WINDOW_WIDTH,100};
    for (int i=0;i<5;i++)
    {
        draw_area[i]={0+i,100+i,WINDOW_WIDTH-i*2,WINDOW_HEIGHT-100-2*i};

    }
}

void SLayout::render(SDL_Renderer* render, Area type)
{
    if (type==Area::Menu)
    {
        SDL_SetRenderDrawColor(render,245,246,247,0);
        SDL_RenderFillRect(render,&menu_area);
        SDL_SetRenderDrawColor(render,218,219,220,0);
        SDL_RenderDrawLine(render,0,1,WINDOW_WIDTH,1);
    }else if (type==Area::Draw)
    {
        SDL_SetRenderDrawColor(render,197,207,223,0);
        for (int i=0;i<5;i++)
        {
            SDL_RenderDrawRect(render,draw_area+i);
        }
    }
}

bool SLayout::inMenuArea(SDL_Event* msg)
{
    return inRect(menu_area,msg->motion.x,msg->motion.y);
}

bool SLayout::inDrawArea(SDL_Event* msgs)
{
    return inRect(draw_area[4],msgs->motion.x,msgs->motion.y);
}

bool SLayout::inRect(SDL_Rect rect, int x, int y)
{
    return (x > rect.x && x <rect.x+rect.w && y >rect.y && y< rect.y+rect.h);
}
